package com.beijing.seventykg.web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.beijing.baseaction.BaseAction;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import com.beijing.seventykg.dao.BookDAO;
import com.beijing.seventykg.po.Book;
import com.beijing.seventykg.service.CacheService;

/**
 * Created by 70kg on 2017-06-28 15:12:31 测试Action
 */
//@Component(value = "testAction")
@Scope(value = "prototype")
@SuppressWarnings({"serial","rawtypes"})
public class TestAction extends BaseAction {
	
	CacheManager cacheManager = CacheManager.getInstance(); 
	Cache cache = cacheManager.getCache("CACHE1");   
	
	@Autowired
	private BookDAO bookDao;
	@Autowired
	private CacheService cacheService;
	private Book book = new Book();
	private String result = "operation is success!!!!";
	HttpServletResponse response = ServletActionContext.getResponse();
	
	private List<Book> list;

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	/**
	 * 测试struts2 跳转是否成功
	 * 
	 * @return
	 */
	public String index() {
		result = "success!!!!";
		return SUCCESS;
	}

	/**
	 * @Description:测试数据库查询
	 * @return
	 * @author 70kg
	 * @date 2018年1月10日下午4:39:31
	 */
	public String testDatabase() {
		list = bookDao.getAllBooks();
		log.info("=========查询数据成功=========");
		return "init_book_data_success";
	}

	public String testCache() {
		String value = cacheService.testCache("helloworld");
		result = "---------cache success ----------";
		return SUCCESS;
	}

	/***
	 * 测试sitemesh
	 * 
	 * @return
	 */
	public String nositemesh() {
		return SUCCESS;
	}

    public List<Book> getList() {
        return list;
    }

    public void setList(List<Book> list) {
        this.list = list;
    }

}